package siskaraoke.servlet.evento;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sistkaraoke.excepcion.DAOExcepcion;
import sistkaraoke.negocio.IGestionSalas;
import sistkaraoke.negocio.GestionSalas;

/**
 * Servlet implementation class InsertarSalaServlet
 */
@WebServlet("/InsertarEventoServlet")
public class InsertarEventoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertarEventoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String nombre = request.getParameter("txtNombre");
		int capacidad = request.getParameter("txtCapacidad").trim().length() > 0 ? 
				Integer.parseInt(request.getParameter("txtCapacidad").trim()) :0;
		String descripcion = request.getParameter("txtdescripcion");
		int idlocal = request.getParameter("local") != "0" ? 
				Integer.parseInt(request.getParameter("local").trim()) :0;		
				
		IGestionSalas negocio = new GestionSalas();
		
		try {
			negocio.insertar(nombre, capacidad, descripcion, idlocal);
			response.sendRedirect(request.getContextPath()	+ "/ListarSalasServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
